﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Library.DAL
{
    public class ChiTietHoaDonNhapDAL
    {
        public static void Add(BIZ.ChiTietHoaDonNhapBIZ cz)
        {
            //i = i + 1;
            NETMobileEntities db = new NETMobileEntities();
            ChiTietHoaDonNhap c = new ChiTietHoaDonNhap();
            c.ID_HoaDonNhap = cz.ID_HoaDonNhap;
            c.ID_SanPham = cz.ID_SanPham;
            c.DonGia = cz.DonGia;
            c.SoLuong = cz.SoLuong;
            db.ChiTietHoaDonNhaps.AddObject(c);
            db.SaveChanges();
        }

        public static List<BIZ.ChiTietHoaDonNhapBIZ> FindByHoaDon(BIZ.HoaDonNhapBIZ h)
        {
            NETMobileEntities db = new NETMobileEntities();
            var r = from a in db.ChiTietHoaDonNhaps
                    where a.ID_HoaDonNhap == h.ID
                    select a;
            List<BIZ.ChiTietHoaDonNhapBIZ> listhoadon = new List<BIZ.ChiTietHoaDonNhapBIZ>();
            BIZ.ChiTietHoaDonNhapBIZ c;
            foreach (DAL.ChiTietHoaDonNhap i in r)
            {
                c = new BIZ.ChiTietHoaDonNhapBIZ();
                c.ID = i.ID;
                c.ID_HoaDonNhap = i.ID_HoaDonNhap;
                c.ID_SanPham = i.ID_SanPham;
                c.DonGia = i.DonGia;
                c.SoLuong = i.SoLuong;

                listhoadon.Add(c);
            }

            return listhoadon;
        }
    }
}
